import {
		Platform,
		Storage_Key,
		ProjectStates,
		ProjectKeys
	} from '@/static/config.js';
	// 文件排序，图片放前面
	export const GetFilesSortFormat = (val) => {
		let fileList = [];
		if (val) {
			val.forEach(item => {
				item.name = item.filename;
				item.type = item.mime;
				item.suffix = item.filename.substring(item.filename.lastIndexOf(".") + 1, item.filename
				.length);
				item.fileid = item.linkid;
				item.url = Platform.api_requestUrl + "/attachment/download/" + item
					.path;
				if (!!item.type && item.type.indexOf("image") > -1) {
					fileList = [item, ...fileList];
				} else {
					fileList = [...fileList, item];
				}
			})
		}
		return fileList;
	}
	// 获取附件第一张图片URL
	export const GetFirstImgFormat = (val) => {
		let tpath = "/static/img/icon/icon_car_def.png";
		let fileList = GetFilesSortFormat(val);
		if (fileList.length > 0) {
			if (!!fileList[0].type && fileList[0].type.indexOf('image') > -1) {
				tpath = Platform.api_requestUrl + "/attachment/download/" + fileList[0].path;
			}
		}
		return tpath;
	}
	export const GetFirstImgFormat2 = (val) => {
		let tpath = "/static/img/icon/icon_car_def.png";
		if (val) {
			let imgs = val.split(',')
			tpath = imgs[0] || tpath;
		}
		return tpath;
	}
